package com.yulintu.common;

import com.yulintu.parser.AbstractBodyParser;
import com.yulintu.dao.BaseBodyDaoService;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;

/**
 * @author caomin
 * @date 2017/10/27
 * @说明
 */
public class StartBodyParser implements Runnable {



    @Override
    public void run() {
        ProcessManager instance = ProcessManager.getProcessManager();
        ArrayBlockingQueue<AbstractBodyParser> abstractBodyParsers = instance.getAbstractBodyParsers();
        ArrayBlockingQueue<BaseBodyDaoService> baseBodyDaoServices = instance.getBaseBodyDaoServices();

        ExecutorService cachedThreadPool = instance.getThreadPool();

        System.out.println("处理bodyParser的阻塞队列，一有数据就开始处理");
        while (true){
            try {
                    AbstractBodyParser  take = abstractBodyParsers.take();
                    //执行方法
                    cachedThreadPool.execute(take);

                    FileBodyResult fileBodyResult = take.getFileBodyResult();
                    BaseBodyDaoService baseBodyDaoService = take.getBaseBodyDaoService();
                    //baseBodyDaoService.setFileBodyResult(fileBodyResult);
                    baseBodyDaoServices.put(baseBodyDaoService);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }


    }
}
